
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.util.Arrays" %>
<%@include file="/public.jsp"%>
<%--
  Created by IntelliJ IDEA.
  User: Yzk20
  Date: 2025/6/24
  Time: 8:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>Title</title>
    <link rel="stylesheet" type="text/css" href="css/styless.css">
</head>
<body>
<nav class="navbar">
    <ul class="nav-list">
        <li><a href="index.jsp" class="nav-link">首页</a></li>
        <li><a href="about.jsp" class="nav-link">关于我们</a></li>
        <%
            if (session.getAttribute("login_account") != null){ %>
        <li><a href="book1.jsp" class="nav-link">图书列表</a></li>
        <li><a href="profile.jsp" class="nav-link">借阅信息</a></li>
        <li><a href="userxx.jsp" class="nav-link">我的账户</a></li>
        <li><a href="quit.jsp" class="nav-link">登出</a></li>
        <% } else { %>
        <!-- 否则显示登录和注册链接 -->
        <li><a href="login.jsp" class="nav-link">登录</a></li>
        <li><a href="register.jsp" class="nav-link">注册</a></li>
        <li><a href="book1.jsp" class="nav-link">图书列表</a></li>
        <% } %>
    </ul>
</nav>
<form>
  <%
    String bookName=request.getParameter("bookName");
    Statement stmt=conn.createStatement();
    String sql="SELECT * FROM books t WHERE " +" 1=1 ";
    if(null!=bookName){
      sql=sql+" AND  t.bookName LIKE '%"+bookName+"%' ";
    }

    ResultSet rs=stmt.executeQuery(sql);
  %>
  <table align="center" >
      <h1 align="center">欢迎进入图书信息</h1>
    <tr>
      <td>图书名称：<input type="text" name="bookName" id="bookName"></td>
    </tr>
    <tr>
      <td align="center" >
        <input type="hidden" name="actionType" id="actionType" value="book">
        <input type="hidden" name="login_account" id="login_account" value="<%=session.getAttribute("login_account")%>">
        <input type="hidden" name="bookid" id="bookid" value="">
        <input type="submit" value="查询" >
<%--        <input type="button" value="添加" onclick="book_add()">--%>
      </td>
    </tr>
  </table>
  <hr>
  <table align="center" width="80%" berder="1" >
    <tr>
      <td>图书ID</td>
      <td>图书名称</td>
      <td>图书类型</td>
      <td>作者</td>
      <td>出版日期</td>
      <td>图书是否被借阅</td>
      <td>操作</td>
    </tr>
    <tbody id="devList">
    <tr>
        <%
    while(rs.next()) {
%>
    <tr>
      <td><%=rs.getString("bookid")%></td>
      <td><%=rs.getString("bookName")%></td>
      <td><%=rs.getString("bookType")%></td>
      <td><%=rs.getString("author")%></td>
      <td><%=rs.getString("date")%></td>
      <td><%=rs.getString("status")%></td>
        <td><input type="button" value="借阅" onclick="rentDev(<%=rs.getString("bookid")%>)"></td>
      <%}%>

    </tr>
    </tbody>
  </table>
</form>
<script>
    function rentDev(bookid) {
        if (document.getElementById("login_account").value == "null") {
            alert("请先登录");
        } else{
            alert("借阅成功");
        document.getElementById("actionType").value = "book_rent";
        document.getElementById("bookid").value = bookid;
        document.forms[0].action = "bookServlet"
        document.forms[0].submit();
        }

    }

</script>
</from>
</body>
</html>
